<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/Frog_32px_1177822_easyicon.net.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/Frog_32px_1177822_easyicon.net.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/Frog_16px_1177822_easyicon.net.ico">
  <link rel="mask-icon" href="/images/Frog_32px_1177822_easyicon.net.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"hxy1997.xyz","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":true,"nav":null,"activeClass":"valine"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"输入关键字","hits_empty":"没有找到与「${query}」相关搜索","hits_stats":"${hits} 条相关记录，共耗时 ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="React的官方教程中就使用了Tic Tac Toe（井字棋）这款游戏作为实战教程引导大家使用React，我自己复现并针对官网教程总结部分的更多要求部分进行了复现，最终得到了完整的Tic Tac Toe游戏。玩过之后怅然若失，也很想要找一些自己感兴趣的项目来磨刀。想到小时候常玩的五子棋游戏，忍不住手痒，很想要自己复现一个，仔细一想了Tic Tac Toe游戏本质上就是五子棋的简化版，为了做出一些小">
<meta property="og:type" content="article">
<meta property="og:title" content="Tic Tac Toe Extended 强化版井字棋">
<meta property="og:url" content="https://hxy1997.xyz/2022/04/15/Tic%20Tac%20Toe%20Extended%20%E5%BC%BA%E5%8C%96%E7%89%88%E4%BA%95%E5%AD%97%E6%A3%8B/index.html">
<meta property="og:site_name" content="hxy的博客">
<meta property="og:description" content="React的官方教程中就使用了Tic Tac Toe（井字棋）这款游戏作为实战教程引导大家使用React，我自己复现并针对官网教程总结部分的更多要求部分进行了复现，最终得到了完整的Tic Tac Toe游戏。玩过之后怅然若失，也很想要找一些自己感兴趣的项目来磨刀。想到小时候常玩的五子棋游戏，忍不住手痒，很想要自己复现一个，仔细一想了Tic Tac Toe游戏本质上就是五子棋的简化版，为了做出一些小">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419111749.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419115506.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419120542.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220420110853.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220420134025.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220420215319.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220422224221.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423214815.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423215633.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423214111.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423220000.png">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220511220900.png">
<meta property="article:published_time" content="2022-04-15T03:30:00.000Z">
<meta property="article:modified_time" content="2022-05-29T07:47:14.886Z">
<meta property="article:author" content="hxy">
<meta property="article:tag" content="React">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="项目">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419111749.png">

<link rel="canonical" href="https://hxy1997.xyz/2022/04/15/Tic%20Tac%20Toe%20Extended%20%E5%BC%BA%E5%8C%96%E7%89%88%E4%BA%95%E5%AD%97%E6%A3%8B/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Tic Tac Toe Extended 强化版井字棋 | hxy的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="hxy的博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">hxy的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Mia san Mia!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/huxingyi1997" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://hxy1997.xyz/2022/04/15/Tic%20Tac%20Toe%20Extended%20%E5%BC%BA%E5%8C%96%E7%89%88%E4%BA%95%E5%AD%97%E6%A3%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/Robben.gif">
      <meta itemprop="name" content="hxy">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="hxy的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Tic Tac Toe Extended 强化版井字棋
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-04-15 11:30:00" itemprop="dateCreated datePublished" datetime="2022-04-15T11:30:00+08:00">2022-04-15</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-05-29 15:47:14" itemprop="dateModified" datetime="2022-05-29T15:47:14+08:00">2022-05-29</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" itemprop="url" rel="index"><span itemprop="name">计算机基础知识</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">热度：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/04/15/Tic%20Tac%20Toe%20Extended%20%E5%BC%BA%E5%8C%96%E7%89%88%E4%BA%95%E5%AD%97%E6%A3%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/04/15/Tic%20Tac%20Toe%20Extended%20%E5%BC%BA%E5%8C%96%E7%89%88%E4%BA%95%E5%AD%97%E6%A3%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>React的<a target="_blank" rel="noopener" href="https://react.docschina.org/tutorial/tutorial.html">官方教程</a>中就使用了Tic Tac Toe（井字棋）这款游戏作为实战教程引导大家使用React，我自己复现并针对官网教程总结部分的<a target="_blank" rel="noopener" href="https://react.docschina.org/tutorial/tutorial.html#wrapping-up">更多要求</a>部分进行了复现，最终得到了完整的<a href="https://hxy1997.xyz/tic-tac-toe/">Tic Tac Toe游戏</a>。玩过之后怅然若失，也很想要找一些自己感兴趣的项目来磨刀。想到小时候常玩的五子棋游戏，忍不住手痒，很想要自己复现一个，仔细一想了Tic Tac Toe游戏本质上就是五子棋的简化版，为了做出一些小改变来增加趣味性，因此决定来做一个伸缩自如的Tic Tac Toe  Extended游戏。</p>
<span id="more"></span>

<h1 id="基础版Tic-Tac-Toe游戏简介"><a href="#基础版Tic-Tac-Toe游戏简介" class="headerlink" title="基础版Tic Tac Toe游戏简介"></a>基础版Tic Tac Toe游戏简介</h1><p>Tic Tac Toe（井字棋）游戏规则：<br>两个玩家，一个画圈圈(O)，一个画叉叉(X)，轮流在3乘3的格上打自己的符号，最先以横、直、斜连成一线则为胜。如果双方都下得正确无误，将得和局。</p>
<p>参考：<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E4%BA%95%E5%AD%97%E6%A3%8B">井字棋介绍</a></p>
<p><a href="https://hxy1997.xyz/tic-tac-toe/">我的Tic Tac Toe</a></p>
<h1 id="Tic-Tac-Toe-Extended游戏功能构想"><a href="#Tic-Tac-Toe-Extended游戏功能构想" class="headerlink" title="Tic Tac Toe  Extended游戏功能构想"></a>Tic Tac Toe  Extended游戏功能构想</h1><p>我们这次要做的是伸缩自如的Tic Tac Toe  Extended游戏，所以我希望有下列功能：</p>
<ol>
<li>棋盘大小可以按照玩家自己设定，例如3x3, 4x4, 5x5….，爱有多大，就有多大。</li>
<li>连成一条直线的胜利条件可以自己设定，意思就是说，可以按自己心意设定连续3子获胜，或是连续5子获胜，直接变成真正的五子棋！(虽然说五子棋好像都是下在棋盘的十字上，我们是下在空格里，但是好像不会影响游戏进行，所以这边先忽略这些细节)。</li>
<li>我们需要一个判断胜负的演算法，告诉我们是谁获胜了，并且标示他获胜棋子的连线。这边的胜负演算法需要适应不同棋盘大小，以及不同胜利条件。</li>
<li>要有一个信息显示版，显示目前轮到谁。当游戏结束，即时显示谁获胜，或和局。</li>
<li>要有一个重新开始的按钮，可以随时重新开始游戏。</li>
<li>可以切换成Single Play模式，也就是说身边没有朋友(哭…)的时候，可以自己跟电脑玩。不过因为我们这次不是以人工只能下棋算法为主题，所以暂时用random算法来让电脑下棋。但是这边会单独设计算法可以方便抽换，之后若有心要让电脑变聪明，直接改演算法就可以了，不需要动到整个程式的架构。</li>
</ol>
<h1 id="开发环境及模板介绍"><a href="#开发环境及模板介绍" class="headerlink" title="开发环境及模板介绍"></a>开发环境及模板介绍</h1><p>我常用的开发环境是<code>create-react-app</code>和<code>react-boilerplate</code>。这边简单引用官方文件介绍一下，会分享一下我选用的理由，另外详细部分我附上连结。</p>
<h3 id="create-react-app"><a href="#create-react-app" class="headerlink" title="create-react-app"></a>create-react-app</h3><blockquote>
<p>Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in React.</p>
</blockquote>
<h5 id="Github-facebook-create-react-app"><a href="#Github-facebook-create-react-app" class="headerlink" title="Github facebook/create-react-app"></a><a target="_blank" rel="noopener" href="https://github.com/facebook/create-react-app">Github facebook/create-react-app</a></h5><h5 id="Create-React-App"><a href="#Create-React-App" class="headerlink" title="Create React App"></a><a target="_blank" rel="noopener" href="https://reactjs.org/docs/create-a-new-react-app.html#create-react-app">Create React App</a></h5><h3 id="react-boilerplate"><a href="#react-boilerplate" class="headerlink" title="react-boilerplate"></a>react-boilerplate</h3><p>The Hitchhikers Guide to react-boilerplate:</p>
<blockquote>
<p>This is a production-ready boilerplate, and as such optimized for browsers, not for beginners. It includes tools to help you manage performance, asynchrony, styling, everything you need to build a real application.</p>
</blockquote>
<h5 id="Github-react-boilerplate"><a href="#Github-react-boilerplate" class="headerlink" title="Github react-boilerplate"></a><a target="_blank" rel="noopener" href="https://github.com/react-boilerplate/react-boilerplate">Github react-boilerplate</a></h5><h5 id="The-Hitchhikers-Guide-to-react-boilerplate"><a href="#The-Hitchhikers-Guide-to-react-boilerplate" class="headerlink" title="The Hitchhikers Guide to react-boilerplate"></a><a target="_blank" rel="noopener" href="https://github.com/react-boilerplate/react-boilerplate/blob/master/docs/general/introduction.md">The Hitchhikers Guide to react-boilerplate</a></h5><h1 id="选择开发环境"><a href="#选择开发环境" class="headerlink" title="选择开发环境"></a>选择开发环境</h1><p>我想选用<code>create-react-app</code>来当作快速开发的环境。虽然说我也蛮喜欢react-boilerplate的，因为react-boilerplate不用再自己一个一个安装redux, reselect, immutableJS, Styled Components…等等常用的package，而且也定期有在更新，Github上面关注的人也蛮多的。</p>
<p>但是我觉得create-react-app比起react-boilerplate更适合入门者，因为create-react-app很好心的帮忙把一些复杂的工具(例如webpack, babel)的配置封装起来，所以大大的降低了入门者的门槛。而且依照我上网找教学文章的经验，觉得比较容易找到create-react-app的相关资料，例如如何快速将ReactJS Web App部署到Github Page上，有很多的参考文章是以create-react-app为例，所以为了让过程顺利的进行，少踩一些雷，这次我先选择create-react-app，让焦点聚焦在代码开发上。</p>
<h1 id="快速建立一个项目"><a href="#快速建立一个项目" class="headerlink" title="快速建立一个项目"></a>快速建立一个项目</h1><p>快速建立一个名为<code>tic-tac-toe-extended</code>的项目</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npx create-react-app tic-tac-toe-extended</span><br></pre></td></tr></table></figure>

<p>ex:</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419111749.png" alt="create-react-app"></p>
<p>进入资料夹之后，执行<code>npm start</code>，即可查看你的app</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> tic-tac-toe-extended</span><br><span class="line">npm start</span><br></pre></td></tr></table></figure>

<p>ex:</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419115506.png" alt="create-react-app_start"></p>
<p>文件结构如下：</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220419120542.png" alt="create-react-app__file-structure"></p>
<h3 id="部署到GitHub-Pages"><a href="#部署到GitHub-Pages" class="headerlink" title="部署到GitHub-Pages"></a>部署到GitHub-Pages</h3><p>通常在这一步的时候，我就会把建立好的项目部署到<code>GitHub-Pages</code>，GitHub-Pages方便我们在GitHub建立静态网站，在展示作品的时候非常方便，而且官网说</p>
<blockquote>
<p>You get one site per GitHub account and organization, and unlimited project sites.</p>
</blockquote>
<p>我之前有一天发现有GitHub-Pages的时候我觉得很不可思议，<code>unlimited project sites</code>!!! 对前端开发者来说是一大福音啊！</p>
<p>部署的详细步骤请容我省略，但是我附上我常参考的链接跟大家分享：</p>
<blockquote>
<p><strong>Deploy React to GitHub-Pages</strong></p>
<h5 id="GitHub-Pages-README-md"><a href="#GitHub-Pages-README-md" class="headerlink" title="GitHub-Pages README.md"></a><a target="_blank" rel="noopener" href="https://create-react-app.dev/docs/deployment/#github-pages">GitHub-Pages README.md</a></h5><h5 id="Deploying-a-React-App-to-GitHub-Pages"><a href="#Deploying-a-React-App-to-GitHub-Pages" class="headerlink" title="Deploying a React App to GitHub Pages"></a><a target="_blank" rel="noopener" href="https://github.com/gitname/react-gh-pages">Deploying a React App to GitHub Pages</a></h5><h5 id="Deploy-React-to-GitHub-Pages-to-create-an-amazing-website"><a href="#Deploy-React-to-GitHub-Pages-to-create-an-amazing-website" class="headerlink" title="Deploy React to GitHub-Pages to create an amazing website!"></a><a target="_blank" rel="noopener" href="https://codeburst.io/deploy-react-to-github-pages-to-create-an-amazing-website-42d8b09cd4d">Deploy React to GitHub-Pages to create an amazing website!</a></h5></blockquote>
<h3 id="Absolute-Imports"><a href="#Absolute-Imports" class="headerlink" title="Absolute Imports"></a>Absolute Imports</h3><p>然后还有一件事情是我会在刚建立好create-react-app项目的时候做，就是我会让我的项目可以在import的时候指定<code>绝对路径</code>，因为有时候指定<code>相对路径</code>会造成我开发上的问题，例如当项目变复杂的时候，我们很容易写出下面这样的东西，很容易写错</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; setInit &#125; <span class="keyword">from</span> ‘../../../../../TicTacToe/actions’;</span><br><span class="line"><span class="keyword">import</span> &#123; selectTicTacToe &#125; <span class="keyword">from</span> ‘../../../../../TicTacToe/selectors;</span><br></pre></td></tr></table></figure>

<p>为了解决这个问题，我还去装了一些VScode的extension，例如<code>Path Autocomplete</code>，来帮助我不要写错。</p>
<p>但是像我们在refactor的时候，或是想要把这段import复制到别的文件里面用的时候，相对路径很容易会改变，所以常被重复使用的import我会干脆写成绝对路径，方便我重复使用。</p>
<p>这边我分享我在设定的时候常会参考的链接：</p>
<blockquote>
<p><strong>Absolute Imports with Create React App</strong></p>
<h5 id="Absolute-Imports-with-Create-React-App"><a href="#Absolute-Imports-with-Create-React-App" class="headerlink" title="Absolute Imports with Create React App"></a><a target="_blank" rel="noopener" href="https://dev.to/mr_frontend/absolute-imports-in-create-react-app-3ge8">Absolute Imports with Create React App</a></h5><h5 id="Setting-Up-Absolute-Paths-in-create-react-app"><a href="#Setting-Up-Absolute-Paths-in-create-react-app" class="headerlink" title="Setting Up Absolute Paths in create-react-app"></a><a target="_blank" rel="noopener" href="https://fdp.io/blog/2018/01/18/setting-up-absolute-paths-in-create-react-app/">Setting Up Absolute Paths in create-react-app</a></h5></blockquote>
<h4 id="补充说明"><a href="#补充说明" class="headerlink" title="补充说明"></a>补充说明</h4><p>如果项目不是透过create-react-app建立的，或是我们的create-react-app已经执行npm run eject了，此时若要让项目可以使用绝对路径，就需要去修改webpack的path.resolve。</p>
<blockquote>
<h5 id="如何扩展Create-React-App-的Webpack-配置"><a href="#如何扩展Create-React-App-的Webpack-配置" class="headerlink" title="如何扩展Create React App 的Webpack 配置"></a><a target="_blank" rel="noopener" href="https://juejin.im/post/5a5d5b815188257327399962">如何扩展Create React App 的Webpack 配置</a></h5><h5 id="ES6-Import-Statement-Without-Relative-Paths-Using-Webpack"><a href="#ES6-Import-Statement-Without-Relative-Paths-Using-Webpack" class="headerlink" title="ES6 Import Statement Without Relative Paths Using Webpack"></a><a target="_blank" rel="noopener" href="https://moduscreate.com/blog/es6-es2015-import-no-relative-path-webpack/">ES6 Import Statement Without Relative Paths Using Webpack</a></h5></blockquote>
<p>总结一下，今天我们介绍了两个不错的开发环境及样板，然后开始了我们的专案，并且也做了一些前置作业，像是可以部署到Github Page方便我们展示作品，以及如何设定绝对路径，方便我们往后的开发。</p>
<p>接下来就要直接写Code啦！我会用到的packages，之后会再边写边介绍。</p>
<h1 id="文件结构规划"><a href="#文件结构规划" class="headerlink" title="文件结构规划"></a>文件结构规划</h1><p>开始一个项目之前，还有一个重要的问题要面对，就是文件结构(File Structure)的规划。特别当项目文件及页面越来越多，功能越来越复杂，好的文件结构规划可以帮助我们在复杂及众多的文件中轻松且快速地找到我们想要的目标代码，也可以帮助我们减少犯错的机会。</p>
<p>但身为一个Reac的入门开发者，在这部分通常会相对没有经验，可以想到的部分没有办法很缜密，所以我上网做了一点功课，并且挑了几篇我自己觉得不错的来跟大家分享。</p>
<p>在React的官方文件里有针对这个问题来做回答：</p>
<blockquote>
<p>Is there a recommended way to structure React projects?<br>React doesn’t have opinions on how you put files into folders. That said there are a few common approaches popular in the ecosystem you may want to consider.</p>
</blockquote>
<h5 id="React的官方文件-File-Structure"><a href="#React的官方文件-File-Structure" class="headerlink" title="React的官方文件: File Structure"></a><a target="_blank" rel="noopener" href="https://reactjs.org/docs/faq-structure.html">React的官方文件: File Structure</a></h5><p>官方文件里面有提到几个重要的原则，但也建议我们<code>Don’t overthink it</code>:</p>
<ol>
<li>Grouping by features or routes</li>
<li>Grouping by file type</li>
<li>Avoid too much nesting</li>
<li>Don’t overthink it</li>
</ol>
<p>根据这些原则，考量到我们的Tic Tac Toe Extended里面不会用到route（路由），然后因为是小游戏，component也不会有复杂结构，所以其实在这个项目文件我们一切从简。</p>
<p>由于我们会用到<code>Redux</code>，在redux 和react 共同构成的架构下，我们将组件分成<code>container</code>和<code>component</code>，container资料夹下面我会放Tic Tac Toe Extended的主要组件，这些组件跟这个项目依赖性较高，而component里面我会放跟这个项目低依赖性的组件，这些组件只被动的接收资料的传入，甚至可以单独抽出来放到别的项目里使用，例如我们需要用的圈圈，叉叉组件，或是我们自己做的按钮等等。</p>
<p>下面是我的文件规划方案，给大家参考:</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220420110853.png" alt="file-structure"></p>
<p>这次因为我们containers下面只会有TicTacToeExtended，所以不会有多个containers下的组件去共用Components里面的元件的状况，这些Components只会被TicTacToeExtended用到，所以我这次就把components放在TicTacToe下面。</p>
<blockquote>
<h5 id="How-to-better-organize-your-React-applications"><a href="#How-to-better-organize-your-React-applications" class="headerlink" title="How to better organize your React applications?"></a><a target="_blank" rel="noopener" href="https://medium.com/@alexmngn/how-to-better-organize-your-react-applications-2fd3ea1920f1">How to better organize your React applications?</a></h5><h5 id="我们如何组织-React-Redux-项目结构"><a href="#我们如何组织-React-Redux-项目结构" class="headerlink" title="我们如何组织 React + Redux 项目结构"></a><a target="_blank" rel="noopener" href="https://starandtina.github.io/articles/Tech/React/2017-06-04-how-we-structure-react-redux-project-stucture.html">我们如何组织 React + Redux 项目结构</a></h5></blockquote>
<h1 id="Tic-Tac-Toe参数存储规划"><a href="#Tic-Tac-Toe参数存储规划" class="headerlink" title="Tic Tac Toe参数存储规划"></a>Tic Tac Toe参数存储规划</h1><h4 id="选用React-Redux架构"><a href="#选用React-Redux架构" class="headerlink" title="选用React + Redux架构"></a>选用React + Redux架构</h4><p>这个项目我会使用到Redux，Redux是为了解决复杂的React App中，有很多层和很复杂的巢状结构，如果要跨Component 之间一层一层的传递参数，会让代码变得很混乱而不容易维护，所以干脆有一个中央控制参数的store来储存所有的state，让需要用到state参数的component直接跟store拿资料即可。所以就可以避免一些component他明明自己不需要这个state，却因为它下面的component需要用到这个state，而硬生生把state传进去又传出来的状况。而且如果传递中的state，在传递过程中，不小心被哪个component无心改动到，就会让除错又变得更棘手。</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220420134025.png" alt="redux-flow"></p>
<p><a target="_blank" rel="noopener" href="https://www.slideshare.net/binhqdgmail/006-react-redux-framework">react-redux-framework</a></p>
<p>根据上面这些理由，我们的Tic Tac Toe好像也不需要用到Redux，因为我们不会有很多不同的component需要彼此传递资料的复杂状况，反而在简单的架构下使用Redux会让专案变得没有必要的复杂。但是因为是应用练习，为了在将来复杂的专案下我们也能很熟练Redux，所以这边我们还是来练习使用一下React + Redux的架构。</p>
<p>因为这次的主题是设定在入门之后的应用练习，所以Redux的详细介绍和安装方式会直接略过，直接进入到文件结构的规划，我的安装设定方式是参考react-boilerplate。我的设定方式或许不是最好的，但是代码也会提供给大家做参考。</p>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://github.com/TimingJL/tic-tac-toe/tree/master/src/store">tic-tac-toe/src/store/</a></p>
</blockquote>
<h4 id="资料储存规划"><a href="#资料储存规划" class="headerlink" title="资料储存规划"></a>资料储存规划</h4><p>我们要来设计state要储存的内容以及储存方式，以下是我设计的参数说明：</p>
<ol>
<li><p>gameScale:</p>
<ul>
<li>因为我们要做的是一个棋盘大小可以伸缩自如的圈圈叉叉游戏，所以我们需要有一个参数来存目前棋盘大小，当调整棋盘大小的时候，只要改变这个参数就可以了，这里我命名为gameScale。例如，当棋盘为3x3的时候，gameScale为3，当棋盘为5x5的时候，gameScale为5。</li>
</ul>
</li>
<li><p>winnerCondition:</p>
<ul>
<li>除了伸缩自如的棋盘之外，我们的胜利条件也可以让玩家自行调整，可以3子连成一直线为获胜，或是调整成5子连成一直线为获胜，所以在winnerCondition储存这个数字，当条件改变的时候，就调整这个参数。</li>
</ul>
</li>
<li><p>blocks:</p>
<ul>
<li><p>这边我用一个物件的阵列来储存棋盘上每一个格子当下的状态，每一个物件有一个id及owner，id用来帮助我在运算的时候找到我想要的那个指定的格子，owner用来储存目前这个格子标示的是圈圈，还是叉叉，还是空的。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">blocks = [&#123;id, owner&#125;, &#123;id, owner&#125;, &#123;id, owner&#125;, &#123;id, owner&#125;, ...]</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>currentRole:</p>
<ul>
<li>顾名思义就是当前是轮到谁要下棋，是圈圈还是叉叉。下面是我在constants.js里面存的参数资料，我用1代表圈圈，用-1代表叉叉，因为我希望乘以-1就可以达到换人的效果。然后下面PLAYER_1意思是游戏开始的时候先攻的人，我这边让圈圈可以先攻。</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> CIRCLE = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> CROSS = -<span class="number">1</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> TOGGLE = -<span class="number">1</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> PLAYER_1 = CIRCLE;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> GAME_WRAPPER_SIZE = <span class="number">600</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> DEFAULT_GAME_SCALE = <span class="number">3</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> DEFAULT_WINNER_CONDITION = <span class="number">3</span>;</span><br></pre></td></tr></table></figure>

<p>tic-tac-toe/src/containers/TicTacToe/constants.js</p>
</li>
<li><p>isSinglePlayer</p>
<ul>
<li><p>我们希望可以切换让自己跟电脑对战的模式，或是跟朋友一起玩的模式，所以isSinglePlayer为true的时候，会让电脑成为你的对手。</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220420215319.png" alt="data-structure."></p>
</li>
</ul>
</li>
</ol>
<h1 id="工具介绍：styled-components"><a href="#工具介绍：styled-components" class="headerlink" title="工具介绍：styled-components"></a>工具介绍：styled-components</h1><p>我在React里面写CSS常用的工具是LESS，本项目想尝试一下styled-components。一般来说，CSS的限制在于没有变量、循环和函数等逻辑，所以我们很难在撰写纯CSS的时候做出复杂的变化。为了解决这个问题，开始出现了在JS上编写CSS的做法， styled-components 是其中一种解决方案。</p>
<p>使用styled-components的好处有很多，例如它可以帮助我们将样式写成更具语义化的组件形式，提高代码可读性。另外有一个我很喜欢的功能，就是可以将React的参数用props的方式传入来控制样式，所以页面的样式就能够透过改变这些参数来做更随心所欲的变化，这两个功能在项目都会使用到。</p>
<p>而且CSS的作用域是全局的，所以命名相同很容易产生冲突，特别是在项目更复杂的时候。但是使用styled-components会为我们生成的React组件产生随机的className，重复使用这些组件的时候随机的className也会不同，因此能够避免组件之间className的冲突，顺利的解决CSS全局作用域的问题。</p>
<p><a target="_blank" rel="noopener" href="https://www.styled-components.com/">styled-components</a><br><a target="_blank" rel="noopener" href="https://medium.com/@perezpriego7/css-evolution-from-css-sass-bem-css-modules-to-styled-components-d4c1da3a659b">CSS Evolution: From CSS, SASS, BEM, CSS Modules to Styled Components</a><br><a target="_blank" rel="noopener" href="https://www.itread01.com/articles/1494952701.html">Styled Components：让样式也成为组件</a></p>
<h1 id="页面布局规划"><a href="#页面布局规划" class="headerlink" title="页面布局规划"></a>页面布局规划</h1><p>在准备好资料之后，我们要开始规划一下我们的页面，下面这个图是我设计的页面雏形。</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220422224221.png" alt="layout-draft"></p>
<p>为了让规划不再是规划，而是能变成实体，我先开始做出整个项目的骨干。<br>我延用create-react-app他原本的App组件作为背景，并包裹<code>&lt;TicTacToe /&gt;</code>组件</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423214815.png" alt="TicTacToe-component"></p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423215633.png" alt="tictactoe-main-draft"></p>
<p>得到的初步布局如下：</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423214111.png" alt="tictactoe-border-layout"></p>
<h3 id="Grid-amp-Flex"><a href="#Grid-amp-Flex" class="headerlink" title="Grid &amp; Flex"></a>Grid &amp; Flex</h3><p>为了要做出设计图的layout，我会喜欢用grid和flex这两个CSS的属性。</p>
<ul>
<li>flex可以帮助我们灵活做出自适应的单轴排版</li>
<li>grid的强项则是在网格状的排版提供了很方便的操作。<br>当页面比较复杂的时候，我会用grid先把网格状的布局定位好，再来用flex调整局部的单一轴向排版。下面分享一些我在学习grid和flex的时候，常会参考的文章及教学影片：</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://www.oxxostudio.tw/articles/201501/css-flexbox.html">深入解析CSS Flexbox</a><br><a target="_blank" rel="noopener" href="https://wcc723.github.io/css/2017/07/21/css-flex/">图解：CSS Flex 属性一点也不难</a><br><a target="_blank" rel="noopener" href="https://wcc723.github.io/css/2017/03/22/css-grid-layout/">CSS Grid 属性介绍</a><br><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=bLbkYuGkQMU&feature=youtu.be">CSS Grid For Everyone</a><br><a target="_blank" rel="noopener" href="http://cssgridgarden.com/">Grid Garden - A game for learning CSS grid</a></p>
<p>上面CSS Grid For Everyone 这位讲者，Part1和Part2讲的内容我觉得还蛮清楚的，帮我厘清很多问题，让我觉得使用grid和flex这两个属性不用再那么害怕，然后讲解过程中也会提到一些实战经验，我觉得很受用，所以推荐给大家。</p>
<p>另外Grid Garden是透过闯关游戏的方式来熟悉grid的语法，还蛮有趣的，也推荐给大家。</p>
<p>不过在使用这两个属性的时候还是需要考虑一下浏览器支持，目前grid还不到90%，所以在使用的时候还是要特别留意。</p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220423220000.png" alt="grid-browser-support"></p>
<p><img data-src="https://cdn.jsdelivr.net/gh/huxingyi1997/my_img/img/20220511220900.png" alt="flex-browser-support"></p>

    </div>

    
    
    
      
<div>
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
</div>
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/React/" rel="tag"><i class="fa fa-tag"></i> React</a>
              <a href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag"><i class="fa fa-tag"></i> 前端</a>
              <a href="/tags/%E9%A1%B9%E7%9B%AE/" rel="tag"><i class="fa fa-tag"></i> 项目</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2022/04/12/%E7%BA%A2%E5%B1%B1%E5%8A%A8%E7%89%A9%E5%9B%AD%E4%B8%80%E6%97%A5%E6%B8%B8%E9%9A%8F%E6%83%B3/" rel="prev" title="红山动物园一日游随想">
      <i class="fa fa-chevron-left"></i> 红山动物园一日游随想
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/04/23/GRID%20GARDEN%E4%B8%AA%E4%BA%BA%E7%AD%94%E6%A1%88/" rel="next" title="GRID GARDEN">
      GRID GARDEN <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9F%BA%E7%A1%80%E7%89%88Tic-Tac-Toe%E6%B8%B8%E6%88%8F%E7%AE%80%E4%BB%8B"><span class="nav-text">基础版Tic Tac Toe游戏简介</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Tic-Tac-Toe-Extended%E6%B8%B8%E6%88%8F%E5%8A%9F%E8%83%BD%E6%9E%84%E6%83%B3"><span class="nav-text">Tic Tac Toe  Extended游戏功能构想</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E5%8F%8A%E6%A8%A1%E6%9D%BF%E4%BB%8B%E7%BB%8D"><span class="nav-text">开发环境及模板介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#create-react-app"><span class="nav-text">create-react-app</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Github-facebook-create-react-app"><span class="nav-text">Github facebook&#x2F;create-react-app</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Create-React-App"><span class="nav-text">Create React App</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#react-boilerplate"><span class="nav-text">react-boilerplate</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Github-react-boilerplate"><span class="nav-text">Github react-boilerplate</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#The-Hitchhikers-Guide-to-react-boilerplate"><span class="nav-text">The Hitchhikers Guide to react-boilerplate</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%80%89%E6%8B%A9%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83"><span class="nav-text">选择开发环境</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%BF%AB%E9%80%9F%E5%BB%BA%E7%AB%8B%E4%B8%80%E4%B8%AA%E9%A1%B9%E7%9B%AE"><span class="nav-text">快速建立一个项目</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%83%A8%E7%BD%B2%E5%88%B0GitHub-Pages"><span class="nav-text">部署到GitHub-Pages</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#GitHub-Pages-README-md"><span class="nav-text">GitHub-Pages README.md</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Deploying-a-React-App-to-GitHub-Pages"><span class="nav-text">Deploying a React App to GitHub Pages</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Deploy-React-to-GitHub-Pages-to-create-an-amazing-website"><span class="nav-text">Deploy React to GitHub-Pages to create an amazing website!</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Absolute-Imports"><span class="nav-text">Absolute Imports</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Absolute-Imports-with-Create-React-App"><span class="nav-text">Absolute Imports with Create React App</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Setting-Up-Absolute-Paths-in-create-react-app"><span class="nav-text">Setting Up Absolute Paths in create-react-app</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%A1%A5%E5%85%85%E8%AF%B4%E6%98%8E"><span class="nav-text">补充说明</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E6%89%A9%E5%B1%95Create-React-App-%E7%9A%84Webpack-%E9%85%8D%E7%BD%AE"><span class="nav-text">如何扩展Create React App 的Webpack 配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#ES6-Import-Statement-Without-Relative-Paths-Using-Webpack"><span class="nav-text">ES6 Import Statement Without Relative Paths Using Webpack</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E7%BB%93%E6%9E%84%E8%A7%84%E5%88%92"><span class="nav-text">文件结构规划</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#React%E7%9A%84%E5%AE%98%E6%96%B9%E6%96%87%E4%BB%B6-File-Structure"><span class="nav-text">React的官方文件: File Structure</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#How-to-better-organize-your-React-applications"><span class="nav-text">How to better organize your React applications?</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%88%91%E4%BB%AC%E5%A6%82%E4%BD%95%E7%BB%84%E7%BB%87-React-Redux-%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84"><span class="nav-text">我们如何组织 React + Redux 项目结构</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Tic-Tac-Toe%E5%8F%82%E6%95%B0%E5%AD%98%E5%82%A8%E8%A7%84%E5%88%92"><span class="nav-text">Tic Tac Toe参数存储规划</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%89%E7%94%A8React-Redux%E6%9E%B6%E6%9E%84"><span class="nav-text">选用React + Redux架构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%B5%84%E6%96%99%E5%82%A8%E5%AD%98%E8%A7%84%E5%88%92"><span class="nav-text">资料储存规划</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%B7%A5%E5%85%B7%E4%BB%8B%E7%BB%8D%EF%BC%9Astyled-components"><span class="nav-text">工具介绍：styled-components</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%A1%B5%E9%9D%A2%E5%B8%83%E5%B1%80%E8%A7%84%E5%88%92"><span class="nav-text">页面布局规划</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Grid-amp-Flex"><span class="nav-text">Grid &amp; Flex</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="hxy"
      src="/images/Robben.gif">
  <p class="site-author-name" itemprop="name">hxy</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">80</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">120</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/huxingyi1997" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;huxingyi1997" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:huxingyi1997@zju.edu.cn" title="E-Mail → mailto:huxingyi1997@zju.edu.cn" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-frog"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">hxy</span>
</div>

<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共1039.2k字</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'pQsO3ySbU4VtWN2j1FLA74Ha-gzGzoHsz',
      appKey     : 'QYacMDY2VY7Wazprg1X6FiUv',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

  
  <!-- 动态背景特效 -->
  <!-- 樱花特效 -->
    <script async src="/js/src/sakura.js"></script>
    <script async src="/js/src/fairyDustCursor.js"></script>
</body>
</html>
